using B.S.NewMedical.Api.Read.Application.Command.Doctor;
using B.S.NewMedical.Api.Read.DTOS.Doctor;
using B.S.NewMedical.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace B.S.NewMedical.Api.Read.Controllers.Doctor
{
    [Route("api/Doctor/[controller]")]
    [ApiController]
    public class DoctorController : ControllerBase
    {
        private readonly IMediator _mediator;

        public DoctorController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取医生列表
        /// </summary>
        /// <param name="doctorName">医生姓名，模糊查询</param>
        /// <param name="deptId">科室ID</param>
        /// <param name="jobTitleId">职称ID</param>
        /// <param name="pageIndex">当前页码，默认1</param>
        /// <param name="pageSize">每页大小，默认10</param>
        /// <returns>医生列表</returns>
        [HttpGet("GetDoctors")]
        public async Task<ApiPageing<DoctorDto>> GetDoctors(
            [FromQuery] string doctorName = null,
            [FromQuery] int? deptId = null,
            [FromQuery] int? jobTitleId = null,
            [FromQuery] int pageIndex = 1,
            [FromQuery] int pageSize = 10)
        {
            return await _mediator.Send(new GetDoctorsCommand(doctorName, deptId, jobTitleId, pageIndex, pageSize));
        }

        /// <summary>
        /// 根据ID获取医生信息
        /// </summary>
        /// <param name="id">医生ID</param>
        /// <returns>医生信息</returns>
        [HttpGet("{id}")]
        public async Task<ApiResult<DoctorDto>> GetDoctorById(int id)
        {
            return await _mediator.Send(new GetDoctorByIdCommand(id));
        }
    }
} 